//
//  BRNewsListCell.m
//  MyBaseProject
//
//  Created by 任波 on 2017/10/5.
//  Copyright © 2017年 任波. All rights reserved.
//

#import "BRNewsListCell.h"
#import "BRHomeModel.h"
#import "UIImageView+BRAdd.h"

@implementation BRNewsListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.iconImageView.hidden = NO;
        self.titleLabel.hidden = NO;
        self.shorttitleLabel.hidden = NO;
        self.contentsLabel.hidden = NO;
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(weakSelf.iconImageView.mas_right).with.offset(10);
        make.height.mas_equalTo(20);
    }];
    [self.shorttitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.titleLabel.mas_bottom).with.offset(5);
        make.left.mas_equalTo(weakSelf.iconImageView.mas_right).with.offset(10);
        make.height.mas_equalTo(20);
    }];
    [self.contentsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.shorttitleLabel.mas_bottom).with.offset(5);
        make.left.mas_equalTo(weakSelf.iconImageView.mas_right).with.offset(10);
        make.right.mas_equalTo(-5);
        make.height.mas_equalTo(40);
    }];
}

- (void)setModel:(BRNewsListModel *)model {
    _model = model;
    [self.iconImageView br_setImageWithPath:model.image placeholder:nil];
    self.titleLabel.text = model.title;
    self.shorttitleLabel.text = model.shorttitle;
    self.contentsLabel.text = model.contents;
}


- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc]init];
        _iconImageView.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:_iconImageView];
    }
    return _iconImageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.font = [UIFont systemFontOfSize:16.0f];
        _titleLabel.textColor = RGB_HEX(0x464646, 1.0f);
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UILabel *)shorttitleLabel {
    if (!_shorttitleLabel) {
        _shorttitleLabel = [[UILabel alloc]init];
        _shorttitleLabel.backgroundColor = [UIColor clearColor];
        _shorttitleLabel.font = [UIFont systemFontOfSize:14.0f];
        _shorttitleLabel.textColor = RGB_HEX(0x999999, 1.0f);
        [self.contentView addSubview:_shorttitleLabel];
    }
    return _shorttitleLabel;
}

- (UILabel *)contentsLabel {
    if (!_contentsLabel) {
        _contentsLabel = [[UILabel alloc]init];
        _contentsLabel.backgroundColor = [UIColor clearColor];
        _contentsLabel.font = [UIFont systemFontOfSize:14.0f];
        _contentsLabel.textColor = RGB_HEX(0x999999, 1.0f);
        _contentsLabel.numberOfLines = 2;
        [self.contentView addSubview:_contentsLabel];
    }
    return _contentsLabel;
}

@end
